/*
 ============================================================================
 Name        : fread_fwrite.c
 Author      : jinzhu
 Version     :
 Copyright   : Your copyright notice
 Description : FreadFwrite in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>

#define SIZE 		65536
#define LENGTH 	1024

int main() {
	char* buf[SIZE] = {0};
	FILE* fp;
	fp = fopen("/usr/include/gnu-versions.h", "r");

	if (NULL != fp)
	{
		if (fread(buf, LENGTH, SIZE/LENGTH, fp) >= 0)
		{
			puts("文件读取成功");
		}
		else
		{
			perror("文件读取失败");
		}
	}
	else
	{
		perror("文件打开失败");
		return 1;
	}
	fclose(fp);

	fp = fopen("copy", "w");

	if (NULL != fp)
	{
		if (fwrite(buf, LENGTH, SIZE/LENGTH, fp) >= 0)
		{
			puts("文件写入成功");
		}
		else
		{
			perror("文件写入失败");
		}
		fclose(fp);
	}
	else
	{
		perror("Copy 文件读取失败");
	}

	return 0;
}
